package com.payment.ktb.utils;

import android.text.TextUtils;

/**
 * Created by syd on 2016/8/31.
 */
public class StringUtils {


    /**
     * 处理手机号 15288888888------》152****8888
     * @param phoneNO
     * @return
     */
    public static String handelPhone(String phoneNO) {

        String hidePhoneNO = null ;

        if (phoneNO == null || phoneNO.length() != 11) {
            return phoneNO;
        }

        hidePhoneNO = phoneNO.substring(0,3) + "****" + phoneNO.substring(phoneNO.length() - 4,phoneNO.length());

        return hidePhoneNO;
    }


    /**
     * 处理身份证 511111111111111111------》5111***1111
     * @param IDNO
     * @return
     */
    public static String handelIDNO(String IDNO) {
        String hideIDNO = null ;


        if (IDNO == null || (IDNO.length() != 15 && IDNO.length() != 18)) {
            return IDNO;
        }

        hideIDNO = IDNO.substring(0 ,4) + "****" + IDNO.substring(IDNO.length() -4 ,IDNO.length());
        return hideIDNO;
    }


    /**
     * 处理银行卡 1242 2345 2342 2343------》1242********2343
     * @param cardNo
     * @return
     */
    public static String handleCard(String cardNo) {


        if (TextUtils.isEmpty(cardNo)) {
            return "";
        }

        if (cardNo.length() < 8) {
            return cardNo;
        }


        String cardHeader = cardNo.substring(0,4);
        String cardBody = "";
        for (int i = 0; i <cardNo.length() - 8 ; i++) {
            cardBody = cardBody + "*";
        }
        String cardFooter = cardNo.substring(cardNo.length()-4,cardNo.length());

        return cardHeader + cardBody + cardFooter;
    }






    public static String handleFen2Yuan(String fen) {
        if (fen.equals("0")) {
            return "0.00";
        }
        double srcFen = Double.valueOf(fen);
        double roundSrcFen = Math.round(srcFen);
        return String.valueOf(roundSrcFen/100);
    }

}
